def print_waitForCompletion( study_dir, jobnames, tmpf ):
    tmpf.write( 'import time\n' )
    tmpf.write( 'import os\n' )
    tmpf.write( 'output_dir = os.path.join(r"' + study_dir + '","outputs")\n' )
    tmpf.write( 'os.chdir( output_dir )\n' )
    tmpf.write( 'import sys\n' )
    tmpf.write( 'os.system( "title Running ABAQUS jobs in %s" % sys.argv[0] )\n' )
    tmpf.write( 'jobnames = [\\\n' )
    for jobname in jobnames:
        tmpf.write( '            "' + jobname + '"' + ',\n' )
    tmpf.write( '           ]\n' )
    tmpf.write( 'total = len(jobnames)\n' )
    tmpf.write( 'job_counter = 0\n' )
    tmpf.write( 'for jobname in jobnames:\n' )
    tmpf.write( '    job_counter += 1\n' )
    tmpf.write( '    #checking if job input file exists\n' )
    tmpf.write( '    tmp = os.path.join( output_dir, jobname + ".inp" )\n' )
    tmpf.write( '    if not os.path.isfile( tmp ):\n' )
    tmpf.write( '        print ("Not found .inp  for: %s at" % jobname), time.ctime()\n' )
    tmpf.write( '        continue\n' )
    tmpf.write( '    #checking if job is already finished\n' )
    tmpf.write( '    tmp = os.path.join( output_dir, jobname + ".msg" )\n' )
    tmpf.write( '    if os.path.isfile( tmp ):\n' )
    tmpf.write( '        msgfile = open( tmp, "r" )\n' )
    tmpf.write( '        lines = msgfile.readlines()\n' )
    tmpf.write( '        msgfile.close()\n' )
    tmpf.write( '        if len( lines ) > 1:\n' )
    tmpf.write( '            if lines[-1].find("       WALLCLOCK") > -1:\n' )
    tmpf.write( '                print ("Skiping  ABAQUS for: %s at" % jobname), time.ctime()\n' )
    tmpf.write( '                continue\n' )
    tmpf.write( '    if os.path.isfile( ("%s.lck" % jobname) ):\n' )
    tmpf.write( '        os.system( "del %s.lck" % jobname )\n' )
    tmpf.write( '    input_file = os.path.join( output_dir, jobname + ".inp" )\n' )
    tmpf.write( '    os.system( "abaqus job=%s input=%s" % (jobname, input_file) )\n' )
    tmpf.write( '    print  "____________________"\n' )
    tmpf.write( '    print  ""\n' )
    tmpf.write( '    print "Counter: job %05d of %05d" % (job_counter, total) \n' )
    tmpf.write( '    print ("Started  ABAQUS for: %s at" % jobname), time.ctime()\n' )
    tmpf.write( '    while True:\n' )
    tmpf.write( '        if os.path.isfile( tmp ):\n' )
    tmpf.write( '            msgfile = open( tmp, "r" )\n' )
    tmpf.write( '            lines = msgfile.readlines()\n' )
    tmpf.write( '            msgfile.close()\n' )
    tmpf.write( '            if len( lines ) > 1:\n' )
    tmpf.write( '                if lines[-1].find("       WALLCLOCK") > -1:\n' )
    tmpf.write( '                    print ("Finished ABAQUS for: %s at" % jobname), time.ctime()\n' )
    tmpf.write( '                    break\n' )
    tmpf.write( '        else:\n' )
    tmpf.write( '            time.sleep(5)\n' )
    tmpf.write( '        time.sleep(10)\n' )
    tmpf.write( 'print  "____________________"\n' )
    tmpf.write( 'print  ""\n' )
    tmpf.write( 'os.system( "title Completed ABAQUS jobs in %s" % sys.argv[0] )\n' )
    tmpf.write( '\n' )

